#include <stdint.h>

#define BITMAP_FORMAT_NONE      	0
#define BITMAP_FORMAT_RGBA_8888		1
#define BITMAP_FORMAT_RGB_565 		4
#define BITMAP_FORMAT_RGBA_4444 	7
#define BITMAP_FORMAT_A_8      		8


#define OP_TYPE_NONE			1000
#define OP_TYPE_GRAYING			1001
#define OP_TYPE_BINARYZATION		1002




typedef int (*UnpackPixel)(unsigned char* pixel, unsigned char* a,
        unsigned char* r, unsigned char* g, unsigned char* b);

typedef struct {
    UnpackPixel unpack;
    uint32_t    width;
    uint32_t    height;
    int32_t     format;
    void *      pixels;
} Bitmap;

typedef struct HistoryNode{
	int op_type;
	Bitmap*		bitmap;
	struct HistoryNode*	pre;
	struct HistoryNode*	next;	 
} HistoryNode;

typedef struct{
	uint32_t depth;
	HistoryNode*	header;
} HistoryStack;

HistoryNode*	peekHistory();
HistoryNode*	popHistory();
uint32_t	pushHistory(HistoryNode* node);
void 		emptyHistory();
int 		graying(float r,float g,float b);
int 		binaryzation(int theshold);
extern Bitmap* bitmap;
extern HistoryStack* historyStack;
void destroyBitmap(Bitmap* bitmap);
int unpack_none(unsigned char* pixel,unsigned char* a,unsigned char* r, unsigned char* g, unsigned char* b);
int unpack_a_8(unsigned char* pixel,unsigned char* a,unsigned char* r, unsigned char* g, unsigned char* b);
int unpack_argb_8888(unsigned char* pixel,unsigned char* a,unsigned char* r, unsigned char* g, unsigned char* b);
int unpack_argb_4444(unsigned char* pixel,unsigned char* a,unsigned char* r, unsigned char* g, unsigned char* b);
int unpack_argb_565(unsigned char* pixel,unsigned char* a,unsigned char* r, unsigned char* g, unsigned char* b);


	
